<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->
<!DOCTYPE html>
<html>
<head>
    <title>Grapheditor</title>
	<script type="text/javascript">
      mxBasePath = '../../editor/www/src';
      log = console;
      var require_exists;
		try {
			var r = require;
			require_exists = true;
		} catch (err) {
			require_exists = false;
		}


		// error collection
		/*window.onerror = function(message, url, lineNumber) {
		    log.error(url);
		    log.error(lineNumber);
		    log.error(message);
		  	return true;
		};*/

	  if (require_exists) {
		   var url = require('url');
		  var fs = require('fs');
		  var querystring = require('querystring');
		  var process = require('process');
		  var path = require('path');
		  const remote = require('electron').remote;

		module.paths.push(path.resolve('node_modules'));
		module.paths.push(path.resolve('../node_modules'));
		// var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
		//var xhr = new XMLHttpRequest();
	  }



   </script>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<link rel="stylesheet" href="extern/jquery-ui.min.css">
  	<!--<link rel="stylesheet" href="/resources/demos/style.css">-->
	<script type="text/javascript">if (typeof module === 'object') {window.module = module; module = undefined;}</script>
	<script type="text/javascript" src="extern/jquery.min.js"></script>
	<script type="text/javascript" src="extern/jquery_ui.min.js"></script>


  	<!--<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>-->
    <link rel="stylesheet" type="text/css" href="styles/grapheditor.css">

	<script type="text/javascript">
		// Parses URL parameters. Supported parameters are:
		// - lang=xy: Specifies the language of the user interface.
		// - touch=1: Enables a touch-style user interface.
		// - storage=local: Enables HTML5 local storage.
		// - chrome=0: Chromeless mode.
		var urlParams = (function(url)
		{
			var result = new Object();
			var idx = url.lastIndexOf('?');
	
			if (idx > 0)
			{
				var params = url.substring(idx + 1).split('&');
				
				for (var i = 0; i < params.length; i++)
				{
					idx = params[i].indexOf('=');
					
					if (idx > 0)
					{
						result[params[i].substring(0, idx)] = params[i].substring(idx + 1);
					}
				}
			}
			
			return result;
		})(window.location.href);
	
		// Default resources are included in grapheditor resources
		mxLoadResources = false;
	</script>
	<script type="text/javascript" src="/media/settings/js_editor_settings.js"></script>
	<script type="text/javascript" src="js/Init.js"></script>
	<script type="text/javascript" src="jscolor/jscolor.js"></script>
	<script type="text/javascript" src="sanitizer/sanitizer.min.js"></script>
	<script type="text/javascript" src="mxClient-debug.js"></script>
	<script type="text/javascript" src="js/EditorUi.js"></script>
	<script type="text/javascript" src="js/Editor.js"></script>
	<script type="text/javascript" src="js/Sidebar.js"></script>
	<script type="text/javascript" src="js/Graph.js"></script>
	<script type="text/javascript" src="js/Shapes.js"></script>
	<script type="text/javascript" src="js/Actions.js"></script>
	<script type="text/javascript" src="js/Menus.js"></script>
	<script type="text/javascript" src="js/Format.js"></script>
	<script type="text/javascript" src="js/Toolbar.js"></script>
	<script type="text/javascript" src="js/Dialogs.js"></script>
	<script type="text/javascript" src="js/Custom.js" defer='defer'></script>

	<script type="text/javascript">if (window.module) {module = window.module; }</script>
</head>
<body class="geEditor">
	<script type="text/javascript">
		// Extends EditorUi to update I/O action states based on availability of backend
		$(document).ready(function()
		{
			var editorUiInit = EditorUi.prototype.init;
			
			EditorUi.prototype.init = function()
			{
				editorUiInit.apply(this, arguments);
				this.actions.get('export').setEnabled(false);

				// Updates action states which require a backend
				if (!Editor.useLocalStorage)
				{
					mxUtils.post(OPEN_URL, '', mxUtils.bind(this, function(req)
					{
						var enabled = req.getStatus() != 404;
						this.actions.get('open').setEnabled(enabled || Graph.fileSupport);
						this.actions.get('import').setEnabled(enabled || Graph.fileSupport);
						this.actions.get('save').setEnabled(enabled);
						this.actions.get('saveAs').setEnabled(enabled);
						this.actions.get('export').setEnabled(enabled);
					}));
				}
			};
			
			// Adds required resources (disables loading of fallback properties, this can only
			// be used if we know that all keys are defined in the language specific file)
			mxResources.loadDefaultBundle = false;
			var bundle = mxResources.getDefaultBundle(RESOURCE_BASE, mxLanguage) ||
				mxResources.getSpecialBundle(RESOURCE_BASE, mxLanguage);

			// Fixes possible asynchronous requests


			if (require_exists) {
				const {BrowserWindow, app} = require('electron').remote;
			    var translation_file = path.join(app.getAppPath(), '/editor/www/resources/grapheditor.txt');
			    var default_style_file = path.join(app.getAppPath(), 'editor', 'www' , 'styles', 'default.xml');
				fs.readFile(translation_file, function(err, data) {
					if (err) {
						console.log(err);
					} else {
						mxResources.parse(data.toString());
					}
				    fs.readFile(default_style_file, function(err, data2) {
						let themes = new Object();
						if (err) {console.log(err);} 
						else {
							// Configures the default graph theme
							var doc = mxUtils.parseXml(data2.toString());
							console.dir(doc.firstChild);
							themes[Graph.prototype.defaultThemeName] = doc.firstChild;
						}
						// Main
						editor_ui = new EditorUi(new Editor(urlParams['chrome'] == '0', themes));
						apply_custom_changes(editor_ui);
					});
				});
			} else {
			    mxUtils.getAll([bundle, STYLE_PATH + '/default.xml'], function(xhr)
				{
					// Adds bundle text to resources
					mxResources.parse(xhr[0].getText());

					// Configures the default graph theme
					var themes = new Object();
					themes[Graph.prototype.defaultThemeName] = xhr[1].getDocumentElement();

					// Main
					editor_ui = new EditorUi(new Editor(urlParams['chrome'] == '0', themes));
					apply_custom_changes(editor_ui);
				}, function()
				{
					document.body.innerHTML = '<center style="margin-top:10%;">Error loading resource files. Please check browser console.</center>';
				});
			}
		});
	</script>
</body>
</html>
